package com.uinnova.product.eam.mvc;

import com.binary.framework.web.RemoteResult;
import com.binary.jdbc.Page;
import com.uinnova.product.eam.model.es.CmdbSysSyncInfo;
import com.uinnova.product.eam.model.es.CmdbSysSyncLog;
import com.uinnova.product.eam.service.CmdbSysSyncService;
import com.uinnova.product.eam.vo.CmdbSysSyncInfoReq;
import com.uinnova.product.vmdb.comm.doc.annotation.ModDesc;
import com.uino.web.auth.VerifyAuthUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/sync/cmdb")
public class CmdbSysSyncController {

    @Resource
    private CmdbSysSyncService cmdbSysSyncService;
    public static final String SYS_MODULE_SIGN = "新建系统调用查询";
    @Resource
    private VerifyAuthUtil verifyAuth;

    @PostMapping("/page")
    @ModDesc(desc = "新建系统调用查询", pDesc = "", rDesc = "", rType = RemoteResult.class)
    public RemoteResult page(@RequestBody CmdbSysSyncInfoReq req) {
        verifyAuth.verifyAuth(SYS_MODULE_SIGN);
        Page<CmdbSysSyncInfo> result = cmdbSysSyncService.page(req);
        return new RemoteResult(result);
    }

    @GetMapping("/logList")
    @ModDesc(desc = "查询推送记录", pDesc = "", rDesc = "", rType = RemoteResult.class)
    public RemoteResult logList(@RequestParam String ciCode) {
        verifyAuth.verifyAuth(SYS_MODULE_SIGN);
        List<CmdbSysSyncLog> result = cmdbSysSyncService.logList(ciCode);
        return new RemoteResult(result);
    }

    @PostMapping("/push")
    @ModDesc(desc = "重新推送", pDesc = "", rDesc = "", rType = RemoteResult.class)
    public RemoteResult push(@RequestBody CmdbSysSyncInfoReq req) {
        verifyAuth.verifyAuth(SYS_MODULE_SIGN);
        CmdbSysSyncLog result = cmdbSysSyncService.push(req);
        return new RemoteResult(result);
    }
}
